<template lang="">
  <t-dialog
    :visible="props.visibles"
    width="40%"
    header="新增报表数据info"
    :confirm-loading="submitLoading"
    :destroy-on-close="true"
    @confirm="handleOnConfirm"
    @cancel="handleClose"
    @close="handleClose"
  >
    <t-form ref="form" :data="formData" :rules="rules">
      <t-form-item label="报表类型" name="reportType">
      <t-input v-model="formData.reportType" placeholder="请输入报表类型"></t-input>
    </t-form-item>
      <t-form-item label="名称" name="name">
      <t-input v-model="formData.name" placeholder="请输入名称"></t-input>
    </t-form-item>
      <t-form-item label="时间" name="sectionDate">
      <t-input v-model="formData.sectionDate" placeholder="请输入时间"></t-input>
    </t-form-item>
      <t-form-item label="上传人员" name="uploadName">
      <t-input v-model="formData.uploadName" placeholder="请输入上传人员"></t-input>
    </t-form-item>
      <t-form-item label="上传时间" name="uploadDate">
      <t-input v-model="formData.uploadDate" placeholder="请输入上传时间"></t-input>
    </t-form-item>
      <t-form-item label="制表时间" name="generateDate">
      <t-input v-model="formData.generateDate" placeholder="请输入制表时间"></t-input>
    </t-form-item>
      <t-form-item label="说明" name="opinion">
      <t-input v-model="formData.opinion" placeholder="请输入说明"></t-input>
    </t-form-item>
      <t-form-item label="备注" name="remark">
      <t-input v-model="formData.remark" placeholder="请输入备注"></t-input>
    </t-form-item>
      <t-form-item label="参数" name="params">
      <t-input v-model="formData.params" placeholder="请输入参数"></t-input>
    </t-form-item>
      <t-form-item label="单位id" name="unitId">
      <t-input v-model="formData.unitId" placeholder="请输入单位id"></t-input>
    </t-form-item>
      <t-form-item label="单位名称（巡查单位）" name="unitName">
      <t-input v-model="formData.unitName" placeholder="请输入单位名称（巡查单位）"></t-input>
    </t-form-item>
      <t-form-item label="创建时间" name="createDate">
      <t-input v-model="formData.createDate" placeholder="请输入创建时间"></t-input>
    </t-form-item>
      <t-form-item label="上传人" name="createId">
      <t-input v-model="formData.createId" placeholder="请输入上传人"></t-input>
    </t-form-item>
      <t-form-item label="更新时间" name="updateDate">
      <t-input v-model="formData.updateDate" placeholder="请输入更新时间"></t-input>
    </t-form-item>
      <t-form-item label="修改人" name="updateId">
      <t-input v-model="formData.updateId" placeholder="请输入修改人"></t-input>
    </t-form-item>
      </t-form>
  </t-dialog>
</template>
<script lang="ts" setup>
import { MessagePlugin } from 'tdesign-vue-next';
import { onMounted, reactive, ref } from 'vue';

import {getList, getInfo, doDelete, doUpdate, doCreate } from '@/api/platform/waterquality/water/report/form';

const props = defineProps({
  visibles: {
    type: Boolean,
    default: false,
  },
});
const INITIAL_DATA = {
        reportType: '',
        name: '',
        sectionDate: '',
        uploadName: '',
        uploadDate: '',
        generateDate: '',
        opinion: '',
        remark: '',
        params: '',
        unitId: '',
        unitName: '',
        createDate: '',
        createId: '',
        updateDate: '',
        updateId: '',
  };
const form = ref();
const submitLoading = ref(false);
const formData: any = reactive({
  ...INITIAL_DATA,
});
const rules = reactive({
        reportType: [
      {
        required: true,
        message: '报表类型必填',
        type: 'error',
        trigger: 'blur',
      },],
        name: [
      {
        required: true,
        message: '名称必填',
        type: 'error',
        trigger: 'blur',
      },],
        sectionDate: [
      {
        required: true,
        message: '时间必填',
        type: 'error',
        trigger: 'blur',
      },],
        uploadName: [
      {
        required: true,
        message: '上传人员必填',
        type: 'error',
        trigger: 'blur',
      },],
        uploadDate: [
      {
        required: true,
        message: '上传时间必填',
        type: 'error',
        trigger: 'blur',
      },],
        generateDate: [
      {
        required: true,
        message: '制表时间必填',
        type: 'error',
        trigger: 'blur',
      },],
        opinion: [
      {
        required: true,
        message: '说明必填',
        type: 'error',
        trigger: 'blur',
      },],
        remark: [
      {
        required: true,
        message: '备注必填',
        type: 'error',
        trigger: 'blur',
      },],
        params: [
      {
        required: true,
        message: '参数必填',
        type: 'error',
        trigger: 'blur',
      },],
        unitId: [
      {
        required: true,
        message: '单位id必填',
        type: 'error',
        trigger: 'blur',
      },],
        unitName: [
      {
        required: true,
        message: '单位名称（巡查单位）必填',
        type: 'error',
        trigger: 'blur',
      },],
        createDate: [
      {
        required: true,
        message: '创建时间必填',
        type: 'error',
        trigger: 'blur',
      },],
        createId: [
      {
        required: true,
        message: '上传人必填',
        type: 'error',
        trigger: 'blur',
      },],
        updateDate: [
      {
        required: true,
        message: '更新时间必填',
        type: 'error',
        trigger: 'blur',
      },],
        updateId: [
      {
        required: true,
        message: '修改人必填',
        type: 'error',
        trigger: 'blur',
      },],
  });
onMounted(() => {
});
const emit = defineEmits(['update:visibles', 'success']);

const handleOnConfirm = () => {
  form.value.validate().then((validateResult: any) => {
    if (validateResult === true) {
      submitLoading.value = true;
      doCreate({
        ...formData,
      }).then(() => {
        submitLoading.value = false;
        MessagePlugin.success('新增报表数据info成功');
        form.value.clearValidate();
        form.value.reset();
        handleClose();
        emit('success');
      });
    } else {
      MessagePlugin.error('表单验证失败');
    }
  });
};

const handleClose = () => {
  emit('update:visibles', false);
};
</script>
<style lang="less" scoped></style>
